<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="com.library.entity.User" %>
<%@ page import="java.util.List" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>图书馆管理系统 - 用户列表</title>
    <style>
        body { font-family: Arial, sans-serif; }
        .sidebar { width: 200px; float: left; }
        .content { margin-left: 220px; }
        .menu { list-style-type: none; padding: 0; }
        .menu li { margin-bottom: 10px; }
        .menu li a { display: block; padding: 5px; background-color: #f1f1f1; text-decoration: none; }
        .menu li a:hover { background-color: #ddd; }
        table { width: 100%; border-collapse: collapse; }
        table, th, td { border: 1px solid #ddd; padding: 8px; }
        th { background-color: #f2f2f2; }
        .role-admin { color: red; }
        .role-user { color: green; }
    </style>
</head>
<body>
    <h1>图书馆管理系统 - 用户列表</h1>
    <div class="sidebar">
        <ul class="menu">
            <li><a href="dashboard.jsp">首页</a></li>
            <li><a href="books">图书管理</a></li>
            <li><a href="addBook.jsp">添加图书</a></li>
            <li><a href="users">用户管理</a></li>
            <li><a href="borrowRecords">借阅记录</a></li>
            <li><a href="../logout">退出登录</a></li>
        </ul>
    </div>
    <div class="content">
        <h2>用户列表</h2>
        <table>
            <tr>
                <th>ID</th>
                <th>用户名</th>
                <th>邮箱</th>
                <th>角色</th>
                <th>操作</th>
            </tr>
            <%
                List<User> users = (List<User>) request.getAttribute("users");
                if (users != null) {
                    for (User user : users) {
            %>
            <tr>
                <td><%= user.getId() %></td>
                <td><%= user.getUsername() %></td>
                <td><%= user.getEmail() %></td>
                <td class="<%= user.getRole() == 1 ? "role-admin" : "role-user" %>">
                    <%= user.getRole() == 1 ? "管理员" : "普通用户" %>
                </td>
                <td>
                    <% if (user.getRole() != 1) { // 不能删除管理员 %>
                    <a href="deleteUser?id=<%= user.getId() %>" onclick="return confirm('确定要删除这个用户吗?')">删除</a>
                    <% } %>
                </td>
            </tr>
            <%
                    }
                }
            %>
        </table>
    </div>
</body>
</html>    